package enumeration;

import java.util.Arrays;

/**
 * Created with IntelliJ IDEA
 * Description:Enum类方法学习
 * User:22954
 * Date:2024-01-27
 * Time:2:30
 */
public class EnumMethod {
    public static void main(String[] args) {
        System.out.println(Season2.AUTUMN.name());//AUTUMN
        /**
         * toString()没有被重写时，返回的是枚举对象名
         */
        System.out.println(Season2.AUTUMN.toString());//AUTUMN
        /**
         * 枚举对象被自动编号，按顺序0,1,2...
         * ordinal()返回对象的编号
         */
        System.out.println(Season2.AUTUMN.ordinal());//2
        System.out.println(Season2.AUTUMN.equals(Season2.EXAMPLE1));//false
        System.out.println(Season2.AUTUMN.equals(Season2.AUTUMN));//true
        System.out.println("==================");
        Season2[] values=Season2.values();
        System.out.println(Arrays.toString(values));//[SPRING, SUMMER, AUTUMN, WINTER, EXAMPLE1, EXAMPLE2]
        /**
         * valueOf()讲字符串强转为枚举对象
         * 必须存在一枚举对象名等于字符串内容
         */
        Season2 season2=Season2.valueOf("AUTUMN");
        System.out.println(Season2.AUTUMN==season2);//true
        /**
         * compareTo()比较的是编号，返回 (引用对象的编号-比较对象的编号)
         */
        System.out.println(Season2.AUTUMN.compareTo(Season2.EXAMPLE1));//-2
    }
}
